package net.tv90.bfmccore.util.HUD;

import lk.vexview.api.VexViewAPI;
import lk.vexview.gui.components.VexImage;
import lk.vexview.hud.VexImageShow;
import lk.vexview.hud.VexTextShow;
import lombok.Data;
import net.tv90.bfmccore.util.vector.Vector2i;
import org.bukkit.entity.Player;

import java.util.Collections;
import java.util.List;

@Data
public class HUD {

    private Player player;
    private String ImagePath;
    private String SoundPath;
    private List<Text> TextList;
    private Vector2i ImagePos;
    private Vector2i ImageScale;
    private int LastTime;

    public HUD() {
    }

    public HUD(Player player, String imagePath, String soundPath, List<Text> textList, Vector2i imagePos, Vector2i imageScale, int lastTime) {
        this.player = player;
        ImagePath = imagePath;
        SoundPath = soundPath;
        TextList = textList;
        ImagePos = imagePos;
        ImageScale = imageScale;
        LastTime = lastTime;
    }

    /**
     * 为玩家展示单个HUD
     * 每个HUD包括一张图片，声音和多条文字
     */
    public void show() {

        player.playSound(player.getLocation(), SoundPath, 100.0F, 1.0F);

        VexImage Icon = new VexImage(ImagePath, ImagePos.getX(), ImagePos.getY(), ImageScale.getX(), ImageScale.getY());
        VexViewAPI.sendHUD(player, new VexImageShow("HUDImage", Icon, LastTime));

        if(TextList != null){
            for(Text t : TextList){
                VexTextShow text = new VexTextShow(
                        "HUDText" + TextList.indexOf(t),
                        t.getTextPos().getX(),
                        t.getTextPos().getY(), 1,
                        Collections.singletonList(t.getContent()), LastTime, t.getTextScale());
                VexViewAPI.sendHUD(player, text);
            }
        }
    }

    /**
     * 添加一条text
     * @param text 文本
     */
    public void addText(Text text){
        TextList.add(text);
    }

    @Override
    public String toString() {
        return "HUD{" +
                "player=" + player +
                ", ImagePath='" + ImagePath + '\'' +
                ", SoundPath='" + SoundPath + '\'' +
                ", TextList=" + TextList +
                ", ImagePos=" + ImagePos +
                ", ImageScale=" + ImageScale +
                ", LastTime=" + LastTime +
                '}';
    }
}
